const totalCountInput = document.getElementById('totalCount');
const totalFeetInput = document.getElementById('totalFeet');
const calculateBtn = document.getElementById('calculate');
const resultPara = document.getElementById('result');

calculateBtn.addEventListener('click', function() {
    const totalCount = parseInt(totalCountInput.value);
    const totalFeet = parseInt(totalFeetInput.value);
    let chicken = -1;
    let rabbit = -1;
    let hasSolution = false;

    for (let i = 0; i <= totalCount; i++) {
        const j = totalCount - i;
        if (2 * i + 4 * j === totalFeet) {
            chicken = i;
            rabbit = j;
            hasSolution = true;
            break;
        }
    }

    if (hasSolution) {
        resultPara.style.color = 'blue';
        resultPara.textContent = `分别有鸡${chicken}只，有兔子${rabbit}只`;
    } else {
        resultPara.style.color = 'red';
        resultPara.textContent = '无解';
    }
});